package com.orion.config.security;

import com.orion.entity.Result;
import com.orion.enumeration.Oauth2ExceptionCodeEnum;
import com.orion.util.ResponseUtil;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.server.ServerAuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @author Administrator
 * @date 2021/11/10
 */
@Component
public class CustomServerAuthenticationEntryPoint implements ServerAuthenticationEntryPoint {

    @Override
    public Mono<Void> commence(ServerWebExchange exchange, AuthenticationException e) {
        System.out.println("basic commence AuthenticationException：" + e);
        Result r = Oauth2ExceptionCodeEnum.UNAUTHORIZED_CLIENT.toResult();
        return ResponseUtil.jsonResp(exchange.getResponse(), r);
    }
}
